$(document).ready(function(){
		
		$(".tel").focus(function () { $(this).mask("(99) 9999?9-9999"); });	
		
		$(".tel").blur(function (){
		
			var phone, element; 
			element = $(this); 
			element.unmask(); 
			phone = element.val().replace(/\D/g, ''); 
			if (phone.length > 10) 
			{ element.mask("(99) 99999-999?9"); } 
			else { element.mask("(99) 9999-9999?9"); } 
		});
		
		 $("#cep").mask("99999-999");  
		 $("#data").mask("99/99/9999");  
		 $("#cpf").mask("999.999.999-99");  
		 $("#cnpj").mask("99.999.999/9999-99");
		
		$( "#tipoEqui" ).change( function(){
		
			var index = document.getElementById("tipoEqui").selectedIndex;  
			var valor = document.getElementById("tipoEqui").options[index].value;
			
			if( valor == "0")
			{
				$('.especificacaoFancoil').css({display:'block'});
				$('.especificacaoSplit').css({display:'none'});
			}
			else if( valor == "1" || valor == "2")
			{
				$('.especificacaoSplit').css({display:'block'});
				$('.especificacaoFancoil').css({display:'none'});
			}
		});

		$("#capacidade").keypress(function (){
		
			var phone, element; 
			element = $(this); 
			element.unmask();
			phone = element.val().replace(/\D/g, ''); 
		
			if (phone.length == 4){ element.mask("9.999"); } 
			else if(phone.length == 5){ element.mask("99.999"); } 
			else if(phone.length == 6){ element.mask("999.999"); }
			
		});
		
		$("#capacidade").focus(function (){
			var element = $(this); 
			element.unmask();
		});
			
		function onlyNumber(elm)
		{
			var valor = $(elm).val().replace(/[^0-9]+/g,'');
			$(elm).val(valor);
		}
		
		function maximumLength(elm, size)
		{
			$(elm).attr('maxlength',''+size+'');
		}
		
		/*--------------Somente Número---------------*/
		$('.onlyNumber').keyup( function() {
			onlyNumber(this);
		});
		
		$("#dijuntor").keyup( function() {
			onlyNumber(this);
		});
					
		/*--------------Limite de Caracteres-------------*/
		/*$( "#capacidade" ).keypress( function(){
			maximumLength(this, 6);
		});*/
		
		$( "#dijuntor" ).keypress( function(){
			maximumLength(this, 4);
		});
		
		$( "#bitolaFio" ).keypress( function(){
			maximumLength(this, 4);
		});
		
		$( "#codigo" ).keypress( function(){
			maximumLength(this, 5);
		});
		
		$( "#grupo" ).keypress( function(){
			maximumLength(this, 3);
		});
		
		$( "#insest" ).keypress( function(){
			maximumLength(this, 15);
		});
		
		$( "#numero" ).keypress( function(){
			maximumLength(this, 15);
		});
		
		$( "#anoFab" ).keydown( function(){
			maximumLength(this, 4);
		});
	
	});  